/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/ccjzxyxt">ccjzxyxt</a> All rights reserved.
 */
package cn.net.dckj.modules.biz.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import cn.net.dckj.common.config.Global;
import cn.net.dckj.common.persistence.Page;
import cn.net.dckj.common.web.BaseController;
import cn.net.dckj.common.utils.StringUtils;
import cn.net.dckj.modules.biz.entity.BizSchoolTimetable;
import cn.net.dckj.modules.biz.service.BizSchoolTimetableService;

/**
 * 课表信息Controller
 * @author xzy
 * @version 2019-04-15
 */
@Controller
@RequestMapping(value = "${adminPath}/biz/bizSchoolTimetable")
public class BizSchoolTimetableController extends BaseController {

	@Autowired
	private BizSchoolTimetableService bizSchoolTimetableService;
	
	@ModelAttribute
	public BizSchoolTimetable get(@RequestParam(required=false) String id) {
		BizSchoolTimetable entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = bizSchoolTimetableService.get(id);
		}
		if (entity == null){
			entity = new BizSchoolTimetable();
		}
		return entity;
	}
	
	@RequiresPermissions("biz:bizSchoolTimetable:view")
	@RequestMapping(value = {"list", ""})
	public String list(BizSchoolTimetable bizSchoolTimetable, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<BizSchoolTimetable> page = bizSchoolTimetableService.findPage(new Page<BizSchoolTimetable>(request, response), bizSchoolTimetable); 
		model.addAttribute("page", page);
		return "modules/biz/bizSchoolTimetableList";
	}

	@RequiresPermissions("biz:bizSchoolTimetable:view")
	@RequestMapping(value = "form")
	public String form(BizSchoolTimetable bizSchoolTimetable, Model model) {
		model.addAttribute("bizSchoolTimetable", bizSchoolTimetable);
		return "modules/biz/bizSchoolTimetableForm";
	}

	@RequiresPermissions("biz:bizSchoolTimetable:edit")
	@RequestMapping(value = "save")
	public String save(BizSchoolTimetable bizSchoolTimetable, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, bizSchoolTimetable)){
			return form(bizSchoolTimetable, model);
		}
		bizSchoolTimetableService.save(bizSchoolTimetable);
		addMessage(redirectAttributes, "保存课表信息成功");
		return "redirect:"+Global.getAdminPath()+"/biz/bizSchoolTimetable/?repage";
	}
	
	@RequiresPermissions("biz:bizSchoolTimetable:edit")
	@RequestMapping(value = "delete")
	public String delete(BizSchoolTimetable bizSchoolTimetable, RedirectAttributes redirectAttributes) {
		bizSchoolTimetableService.delete(bizSchoolTimetable);
		addMessage(redirectAttributes, "删除课表信息成功");
		return "redirect:"+Global.getAdminPath()+"/biz/bizSchoolTimetable/?repage";
	}

}